home *** CD-ROM | disk | FTP | other *** search
/ Aminet 21 / Aminet 21 (1997)(GTI - Schatztruhe)[!][Oct 1997].iso / Aminet / comm / mail / TASC.lha / tasc / rexx / AltSpam.thor next >
Encoding:
Text File  |  1997-07-03  |  6.4 KB  |  284 lines

  1. /* $VER: AltSpam.thor V0.4 (29/6/97)
  2. *  Takes an unsuccessful complaint & parses out the real & IP addresses to
  3. *  add to a file. This file can be used by TASC.thor to tell you when it's pointless
  4. *  to complain & to offer you an alternative address.
  5. *  Also gives you the option to resend your original complaint.
  6. */
  7.  
  8.  
  9. /*============Don't change anything below here==================*/
  10.  
  11. options results
  12. options failat 31
  13.  
  14. /* Read the config file & set up defalts if it isn't there */
  15. if open(cfg,'Env:thor/TASC.cfg',r) then do
  16.    do until eof(cfg)
  17.        lin=readln(cfg)
  18.        parse var lin id ':' V
  19.        V=strip(V)
  20.        if upper(left(id,6))='BOUNCE' then
  21.           Bounce=V
  22.        if upper(left(id,4))='MINE' then
  23.           Mine=V
  24.        if upper(left(id,10))='POSTMASTER' then
  25.           Postmaster=V
  26.        if upper(left(id,8))='DATABASE' then
  27.           spamdb=V
  28.     end
  29.     call close(cfg)
  30. end
  31. else do
  32.     Bounce=''
  33.     Mine=''
  34.     Postmaster=''
  35.     spamdb='rexx/spam.db'
  36. end
  37.  
  38. FRM=''
  39. failed.=''
  40. spamfail.=''
  41. email.=''
  42. i=1
  43.  
  44. thorport = address()
  45. if left(thorport, 5) ~= 'THOR.' then do
  46.   say 'Cannot find thorport.'
  47.   exit
  48. end
  49.  
  50. if ~show('p', 'BBSREAD') then do
  51.   address command
  52.   "run >nil: `GetEnv THOR/THORPath`bin/LoadBBSRead"
  53.   "WaitForPort BBSREAD"
  54. end
  55.  
  56. if open(A,'env:thor/thorpath') then do
  57.     THORP=READLN(A)
  58.     call close(A)
  59. end
  60.  
  61. address(thorport)
  62.  
  63. CURRENTMSG stem MSG
  64. if (rc ~= 0) then call oops("No current message.")
  65.  
  66. SAVEMESSAGE CURRENT FILE "T:AltSpam.temp"
  67. if(rc ~= 0) then call oops("Unable to save current message.")
  68.  
  69. IF Open(A,'T:Altspam.temp','r') = 0 THEN DO
  70.         call oops("Couldn't open temporary file")
  71.         EXIT 20
  72.         END
  73.  
  74. do until index(hder,'X-Mailer: THOR')~=0
  75.     /* A header line belonging to Thor. We assume that no one runs their
  76.        mailserver with Thor */
  77.     hder= readln(A)
  78.     if upper(left(hder,5))='FROM:' then do
  79.         Call FRM
  80.     end
  81.     if upper(left(hder,3))='TO:' then do
  82.         Call TOHDR
  83.     end
  84.     if upper(left(hder,9))='ORIGINAL-' then do
  85.         Call ORIG
  86.         end
  87.     if upper(left(hder,6))='FINAL-' then do
  88.         Call FIN
  89.         end
  90. end
  91. close(A)
  92.  
  93. /* Now ask what we should do the next time that we meet these addresses  */
  94. if open(A,THORP||spamdb,'r') then do
  95.     DO WHILE ~Eof(A)
  96.         f=readln(A)
  97.         parse VAR f wrong '->' correct
  98.         do j=1 to i
  99.           parse VAR spamfail.j gubbins ':' addr
  100.           if wrong=addr then do
  101.               spamfail.j=''
  102.           end
  103.         end
  104.     END
  105. end
  106. a=1
  107. do j=1 to i
  108.     if spamfail.j~='' then do
  109.         failed.a=spamfail.j
  110.         a=a+1
  111.     end
  112. end
  113. failed.count=a-1
  114. if failed.count<1 then call oops("All addresses are assigned already.\n Try editing the "||THORP||spamdb||" file by hand.")
  115. drop spamfail.
  116.  
  117. address(Thorport)
  118.  
  119. Requestlist Instem failed outstem spamfail dragselect multiselect title '"Add which addresses?"'
  120. IF (RC > 0) THEN call oops("No Addresses Selected")
  121.  
  122. do i=1 to failed.count
  123. parse VAR failed.i gubbins ':' failed.i
  124. end
  125.  
  126. do i=1 to spamfail.count
  127. parse VAR spamfail.i gubbins ':' spamfail.i
  128. end
  129.  
  130. k=2
  131. do i=1 to spamfail.count
  132.     drop email.
  133.     email.1='Mark as Undeliverable'
  134.     if FRM~='' then do
  135.         email.k=FRM
  136.         k=k+1
  137.     end
  138.     Call ParseAlt
  139.     Call PickAlt
  140.     call Remail
  141. end
  142.  
  143. call cleanup
  144.  
  145. FRM:
  146. if index(hder,mine)=0 then do
  147.     parse VAR hder gubbins '<' pm '@' FRM '>'
  148. end
  149. return
  150.  
  151. TOHDR:
  152. parse VAR hder gubbins '<' pm '@' TOHDR '>'
  153. if TOHDR=Bounce then return
  154. if index(TOHDR,',')~=0 then do until index(TOHDR,',')=0
  155.     parse VAR TOHDR tohd ',' pm '@' TOHDR
  156.     spamfail.i='[TO Postmaster@    ]:'||tohd
  157.     i=i+1
  158. end
  159. spamfail.i='[TO Postmaster@    ]:'||TOHDR
  160. spamfail.count=i
  161. i=i+1
  162. return
  163.  
  164. ORIG:
  165. parse VAR hder gubbins ';' pm '@' ORIG
  166. spamfail.i='[Original-Recipient]:'||ORIG
  167. spamfail.count=i
  168. i=i+1
  169. return
  170.  
  171. FIN:
  172. parse VAR hder gubbins ';' pm '@' FIN
  173. spamfail.i='[Final-Recipient   ]:'||FIN
  174. spamfail.count=i
  175. i=i+1
  176. return
  177.  
  178. ParseAlt:
  179. if left(spamfail.i,1)='[' then do
  180.     do j=1 to failed.count
  181.         if left(failed.j,1)~='[' then do
  182.             baseaddr=failed.j
  183.             Call parseaddr
  184.             parsed='Y'
  185.         end
  186.     end
  187.     if parsed~='Y' then do
  188.         email.k='No alternative addresses'
  189.         k=k+1
  190.     end
  191. end
  192. else do
  193.     baseaddr=spamfail.i
  194.     Call Parseaddr
  195. end
  196. return
  197.  
  198. Parseaddr:
  199.   email.k=baseaddr
  200.   k=k+1
  201.   do until index(baseaddr,'.')=0
  202.      parse VAR baseaddr lwr '.' hghr
  203.      if index(hghr,'.')~=0 then do
  204.          email.k=hghr
  205.          k=k+1
  206.      end
  207.      baseaddr=hghr
  208.   end
  209. return
  210.  
  211. PickAlt:
  212. email.count=k-1
  213. newaddr.=''
  214. Requestlist Instem email outstem newaddr title '"Substitute which address for '||spamfail.i||'?"'
  215. IF (RC > 0) THEN DO
  216.    REQUESTNOTIFY TEXT '"No Addresses Selected"' BT '"_Ok"'
  217.    return
  218. END
  219. newaddr=result
  220.     if newaddr='No alternative addresses' then
  221.         newaddr='Undeliverable'
  222.     if newaddr='Mark as Undeliverable' then
  223.         newaddr='Undeliverable'
  224.     address command
  225.     'echo '||spamfail.i||'->'||newaddr||' >> '||THORP||spamdb
  226. return
  227.  
  228. Remail:
  229. address(thorport)
  230. if newaddr='Undeliverable' then return
  231. if newaddr~=spamfail.i then do
  232.     adder='Remail complaint to '||newaddr||' (was '||spamfail.i||')?'
  233.     requestnotify text '"' adder '"' BT '"_Yes|_No"'
  234.     if result=0 then return
  235.     if open(A,'T:altspam.temp','r')>0 then do
  236.         hder=readln(A)
  237.         do until index(hder,'X-Mailer: THOR')~=0
  238.             hder=readln(A)
  239.         end
  240.         CURRENTMSG stem MSG
  241.         address bbsread
  242.         UNIQUEMSGFILE bbsname '"'MSG.BBSNAME'"' stem tmp
  243.         if (rc ~= 0) then call oops
  244.         if open(B,tmp.NAME,'w')>0 then do
  245.             if Postmaster~='' then do
  246.                 call Writeln (B,'"From: postmaster@'||Postmaster||'"')
  247.                 call Writeln (B,"")
  248.             end
  249.             do until eof(A)
  250.                 hder=readln(A)
  251.                 writeln(B,hder)
  252.             end
  253.             call close(B)
  254.         end
  255.         call close(A)
  256.     end
  257.     EVE_ENTERMSG = 0
  258.     drop EVENT.
  259.     EVENT.TONAME = 'Postmaster'
  260.     EVENT.TOADDR = 'Postmaster@'||newaddr
  261.     EVENT.SUBJECT = 'Spam/Email abuse'
  262.     EVENT.CONFERENCE = 'EMail'
  263.     EVENT.MSGFILE = tmp.FILEPART
  264.     EVENT.URGENT = 0
  265.     WRITEBREVENT bbsname '"'MSG.BBSNAME'"' event EVE_ENTERMSG stem EVENT
  266. end
  267. return
  268.  
  269. oops:
  270.   PARSE ARG errmsg
  271.   if errmsg = '' then do
  272.     if address() = "BBSREAD" then errmsg=BBSREAD.LASTERROR
  273.     else errmsg=THOR.LASTERROR
  274.   end
  275.   address(thorport)
  276.   REQUESTNOTIFY TEXT '"' errmsg '"' BT '"_Abort"'
  277.   call cleanup
  278. return
  279.  
  280.  
  281. cleanup:
  282.   address command 'delete >nil: T:AltSpam.temp'
  283. exit
  284.